﻿using System.Diagnostics;
using System.Reflection;
using YAXLib;

namespace RaytracerLib.Script
{
    public class ScriptParam
    {
        [YAXNode]
        public readonly string Name;

        private FieldInfo m_field;
        private object m_script;
        private object m_value;

        public ScriptParam()
        {
        }

        public ScriptParam(string a_name, object a_script, FieldInfo a_field)
        {
            Debug.Assert(a_name == a_name.Trim());
            Debug.Assert(a_name.Length > 0);

            Name = a_name;
            m_field = a_field;
            m_script = a_script;
        }

        [YAXNode]
        public object Value
        {
            get
            {
                if (m_field == null)
                    return m_value;
                else
                    return m_field.GetValue(m_script);
            }
            set
            {
                if (m_field == null)
                    m_value = value;
                else
                    m_field.SetValue(m_script, value);
            }
        }
    }
}